<%@ page import="com.afc.struts.bustle.products.ProductsForm"%>
<%@ page
	import="com.afc.struts.bustle.products.ProductsForm.DefaultProductsForm"%>
<%@ page import="com.afc.struts.bustle.model.ProductDto"%>
<%@ page import="java.util.Iterator"%>
<%@ page import="com.afc.struts.utils.DateUtils"%>

<%
  String error = (String) request.getAttribute("error");
			ProductsForm form = (ProductsForm) request.getAttribute("form");
			if (form == null) {
				form = new DefaultProductsForm();
			}
%>

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript">
	function submitForm(anActionUrl, aFormElement) {
		aFormElement.action = anActionUrl;
		aFormElement.submit();
	}
</script>
</head>

<body>
	<div style="height: 50px;">
		<a href="welcome.jsp">Retour vers la page d'accueil</a>
	</div>
	<form method="post">
		Products :
		<table border=1 style="border-collapse:collapse;text-align: center;">
			<tr>
				<th style="padding: 5px;">Id</th>
				<th style="padding: 5px;">Type</th>
				<th style="padding: 5px;">Provider</th>
				<th style="padding: 5px;">Name</th>
				<th style="padding: 5px;">Price</th>
				<th style="padding: 5px;">CreationDate</th>
				<th style="padding: 5px;">LimitationDate</th>
				<th style="padding: 5px;">Image</th>
			</tr>
			<%
			  Iterator iterator = form.getProducts().iterator();
			  for (int i = 0; iterator.hasNext(); i++)
			  {
			    ProductDto product = (ProductDto)iterator.next();
			%>
			<tr>
				<td><input type="radio" attribute-type="int"
					name="selectedProductId" value="<%=product.getIdProduct()%>"
					<%=form.getSelectedProductId() == product.getIdProduct() ? "checked" : ""%>><%=product.getIdProduct()%></input>
				</td>
				<td><%=product.getProductType()%></td>
				<td><%=product.getProvider()%></td>
				<td><%=product.getName() != null ? product.getName() : ""%></td>
				<td><%=product.getPrice()%></td>
				<td><%=product.getCreationDate() != null ? DateUtils.format(product.getCreationDate()) : ""%>
				</td>
				<td><%=product.getLimitedDate() != null ? DateUtils.format(product.getLimitedDate()) : ""%>
				</td>
				<td><%=product.getImage() != null ? product.getImage() : ""%>
				</td>
			</tr>
			<%
			  }
			%>
		</table>
		<br /> <input type="button" value="Add"
			onclick='submitForm("products.add.do", this.form)' /> <input
			type="button" value="Update"
			onclick='submitForm("products.update.do", this.form)' /> <input
			type="button" value="Remove"
			onclick='submitForm("products.remove.do", this.form)' /> <label><%=error != null ? error : ""%></label>
	</form>

</body>

</html>